package com.alongthink.javademo.controller;

import com.alongthink.javademo.annotation.ApiRestController;
import com.alongthink.javademo.annotation.OperationLogDetail;
import com.alongthink.javademo.globalClass.ResultBody;
import com.alongthink.javademo.globalcatch.AlongException;
import com.alongthink.javademo.globalcatch.BaseReturnEnum;
import com.alongthink.javademo.utilTools.ExportExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

@Api(tags = "前端HomeController控制器")
@ApiRestController
@Slf4j
public class HomeController {
    @Autowired
    private RedisTemplate redisTemplate;
    //写入用户日志
    @GetMapping("/name")
    @OperationLogDetail
    @ApiOperation(value = "测试日志写入")
    public ResultBody getName(String dd){
        log.info("==================");
        return ResultBody.success();
    }

    @GetMapping("/sendMsgToRedis")
    @OperationLogDetail
    @ApiOperation(value = "发送消息到reids")
    public ResultBody sendMsgToRedis(String dd){
        log.info("==================");
        byte[] bytes = dd.getBytes();
        redisTemplate.convertAndSend("msg",bytes);//发送数据到redis
        return ResultBody.success();
    }

    @GetMapping("/returnErrorInfo")
    @OperationLogDetail
    @ApiOperation(value = "发送消息到reids")
    public ResultBody returnErrorInfo(){
        log.info("==================");
        return ResultBody.error(BaseReturnEnum.FAIL);
    }

    @GetMapping("/throwCustomizeException")
    @OperationLogDetail
    @ApiOperation(value = "抛出自定义异常")
    public ResultBody throwCustomizeException(){
        throw new AlongException();
    }

    @GetMapping("/throwException")
    @OperationLogDetail
    @ApiOperation(value = "抛出异常")
    public ResultBody throwException(){
        throw new ArrayIndexOutOfBoundsException();
    }


}
